﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex03.GarageLogic
{
    /// <summary>
    /// Motorcycle is a class that inherit <see cref="GarageLogic.Vehicle" />  and have also the properties:
    /// 1. Lisence type
    /// 2. Engine capacity in Cc.
    /// </summary>
    internal class Motorcycle : Vehicle
    {
        private enum eLicenseType
        {
            A,
            A1,
            A2,
            B
        }

        private eLicenseType m_LicenseType = 0;
        private int m_EngineCapacity = 0;

        public Motorcycle(string i_VehicleModelName, string i_VehicleLicenseNumber, Wheel[] i_WheelsArary, EnergySource i_EnergySource)
            :base(i_VehicleModelName, i_VehicleLicenseNumber, i_WheelsArary, i_EnergySource)
        {
        }

        /// <summary>
        /// Overriding <see cref="Object.ToString"/>
        /// </summary>
        /// <returns>All the info of the motorcycle formatted as on string</returns>
        public override string ToString()
        {
            string toString = string.Empty;

            toString = string.Format(@"
{0}
License type: {1}
Engine capacitiy: {2}"
                , base.ToString()
                , m_LicenseType
                , m_EngineCapacity);

            return toString;
        }

        /// <summary>
        /// Overriding <see cref="GarageLogic.Vehicle.GetSpecificProperties"/>
        /// </summary>
        /// <returns> List of strings that represnts messages for the Ui </returns>
        public override List<string> GetSpecificProperties()
        {
            List<string> listOfspecificProperties = new List<string>();

            string colorMessage = getPropertyMessageOfEnum("Enter license type from:", typeof(eLicenseType));
            listOfspecificProperties.Add(colorMessage.ToString());
            listOfspecificProperties.Add("Enter engine capacity: ");

            return listOfspecificProperties;
        }

        /// <summary>
        /// Overriding <see cref="GarageLogic.Vehicle.SetSpecificProperties"/> sets in Motorcycle his specific properties
        /// </summary>
        /// <param name="i_ListOfSpecificVehiclePropertiesFromUser">List of user inputs from the UI </param>
        public override void SetSpecificProperties(List<string> i_ListOfSpecificVehiclePropertiesFromUser)
        {
            const bool v_CaseSensitive = true;
            eLicenseType licenseTypeResult = 0;
            int engineCapacityResult = 0;
            bool isParseCorrect = false;
            isParseCorrect = Enum.TryParse(i_ListOfSpecificVehiclePropertiesFromUser[0], v_CaseSensitive, out licenseTypeResult);
            isParseCorrect = Enum.IsDefined(typeof(eLicenseType), licenseTypeResult);
            if (isParseCorrect)
            {
                m_LicenseType = licenseTypeResult;
            }
            else
            {
                throw new FormatException("type of lisence is not match");
            }

            isParseCorrect = int.TryParse(i_ListOfSpecificVehiclePropertiesFromUser[1], out engineCapacityResult);            
            if (isParseCorrect)
            {
                if (engineCapacityResult < 0)
                {
                    throw new ArgumentException("negative number of engine capacity is not allowed");
                }
                else
                {
                    m_EngineCapacity = engineCapacityResult;
                }
            }
            else
            {
                throw new FormatException("it is not a number");
            }
        }
    }
}